﻿using NewRen.Log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;

namespace NewRen.Schemas
{
    public class CustomExceptionAttribute : HandleErrorAttribute
    {
        /// <summary>
        /// 异常
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnException(ExceptionContext filterContext)
        {
            //使用log4net或其他记录错误消息
            Exception Error = filterContext.Exception;
            string Message = Error.Message;//错误信息
            string Url = HttpContext.Current.Request.RawUrl;//错误发生地址
            log4net.ILog log = log4net.LogManager.GetLogger("myLogger");
            filterContext.ExceptionHandled = true;

            log.Error(new LogContent(Message, Helpers.HttpHelper.GetIPAddress()));
            filterContext.Result = new RedirectResult("/Shared/Info/?msg=500");//跳转至错误提示页面
        }
    }
}
